app.factory('UploadService', function(ConfigMap) {

	var uploadImage = function(imageURI, successCallback, errorCallback){
		var options = new FileUploadOptions();
		options.mimeType = "image/jpeg";
		upload(imageURI, options, successCallback, errorCallback);
	};

	var uploadWav = function(radioURI, successCallback, errorCallback){
		radioURI = 'file:///storage/emulated/0/' + radioURI;
		var options = new FileUploadOptions();
		options.mimeType = "audio/x-wav";
		upload(radioURI, options, successCallback, errorCallback);
	};

	function upload(fileUri, options,successCallback, errorCallback){
		options.fileName = fileUri.substr(fileUri.lastIndexOf('/')+1);
		options.fileKey  = 'file';
		new FileTransfer().upload(fileUri, encodeURI(ConfigMap.uploadUrl), function(data){
			if(successCallback){
				successCallback(JSON.parse(data.response));
			}
		}, function(err){
			alert('upload errorrrr');
			writeObj(err);
			if(errorCallback){
				errorCallback(err);
			}
		}, options);
	}
	return {
		uploadImage:uploadImage,
		uploadWav  :uploadWav
	};
});